<template>
  <div class="app-container">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
                 label-width="68px">

          <el-form-item label="" prop="customerId">
            <el-select
              v-model="queryParams.customerId"
              :placeholder="$t('customer')"
              clearable
              style="width: 240px"
            >
              <el-option
                v-for="item in userList"
                :key="item.userId"
                :label="item.userName"
                :value="item.userId"
              />
            </el-select>
          </el-form-item>

          <el-form-item label="">
            <el-date-picker
              v-model="dateRange"
              style="width: 240px"
              value-format="yyyy-MM-dd"
              type="daterange"
              range-separator="-"
              :start-placeholder="$t('startTime')"
              :end-placeholder="$t('endTime')"
            ></el-date-picker>
          </el-form-item>

          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">{{ $t('search') }}</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t('reset') }}</el-button>
          </el-form-item>
        </el-form>

    <el-row :gutter="40" class="panel-group">
      <el-col :xs="16" :sm="16" :lg="8" class="card-panel-col">
        <div class="card-panel">
          <div class="card-panel-description" style="text-align: center">
            <div class="card-panel-text" >
              {{ $t('umberOfOrders') }}
            </div>
            <span>
              {{totalMap.num}}
            </span>
          </div>
        </div>
      </el-col>
      <el-col :xs="16" :sm="16" :lg="8" class="card-panel-col">
        <div class="card-panel">
          <div class="card-panel-description" style="text-align: center">
            <div class="card-panel-text" >
              {{ $t('loanSuccessNum') }}
            </div>
            <span>
              {{totalMap.num1}}
            </span>
          </div>
        </div>
      </el-col>
      <el-col :xs="16" :sm="16" :lg="8" class="card-panel-col">
        <div class="card-panel">
          <div class="card-panel-description" style="text-align: center">
            <div class="card-panel-text" >
              {{ $t('loanSuccessRate') }}
            </div>
            <span>
              {{totalMap.num1/totalMap.num | numFilter}}%
            </span>
          </div>
        </div>
      </el-col>
    </el-row>

        <el-table border v-loading="loading" :data="indexList" style="margin-top: 20px;">
          <el-table-column type="index" width="50"/>
          <el-table-column :label="$t('date')" align="center" prop="buildDate"/>
          <el-table-column :label="$t('customer')" align="center" prop="userName"/>
          <el-table-column :label="$t('umberOfOrders')" align="center" prop="num"/>
          <el-table-column :label="$t('loanSuccessNum')" align="center" prop="num1"/>
          <el-table-column :label="$t('withdrawalRate')" align="center" prop="num1">
            <template slot-scope="scope">
              {{scope.row.num1 / scope.row.num | numFilter}}%
            </template>
          </el-table-column>
          <el-table-column :label="$t('loanDayNumber')" align="center" prop="num2"/>
        </el-table>
        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />

  </div>
</template>

<script>
import {listPayData,payDataTotal} from "@/api/app/data/data";
import {customerUserList} from "@/api/system/user"
export default {
  name: "CompanyData",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 用户表格数据
      indexList: null,
      userList: null,
      totalMap: {},
      companyList: null,
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 日期范围
      dateRange: [],
      channelList: [],
      // 表单参数
      form: {},
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        customerId: undefined,
        beginTime: undefined,
        endTime: undefined
      },
    };
  },
  watch: {},
  created() {
    this.getList();
    this.getTotal();
    this.getOneExamineList();
  },
  methods: {
    /** 查询列表 */
    getList() {
      this.loading = true;
      if (this.dateRange) {
        this.queryParams.beginTime = this.dateRange[0];
        this.queryParams.endTime = this.dateRange[1];
      } else {
        this.queryParams.beginTime = undefined;
        this.queryParams.endTime = undefined;
      }
      listPayData(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
          this.indexList = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      );
    },

    getTotal(){
      payDataTotal(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
          this.totalMap = response.data;
        }
      );
    },

    getOneExamineList() {
      customerUserList().then(response => {
          this.userList = response.data;
        }
      );
    },


    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },

    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        applyMoney: 0,
        manageMoney: 0,
        examineMoney: 0,
        serviceMoney: 0,
        cycle: 0,
        realMoney: 0,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
      this.getTotal();
      // this.getTotalList();
    },

    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id;
      getIndexApply(id).then(response => {
        this.form = response.data;
        this.form.realMoney = this.form.applyMoney - this.form.manageMoney - this.form.examineMoney - this.form.serviceMoney;
        this.open = true;
        this.title = "修改";
      });
    },


    /** 提交按钮 */
    submitForm: function () {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != undefined) {
            updateIndexApply(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addIndexApply(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除编号为"' + ids + '"的数据项？').then(function () {
        return delIndexApply(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },

    handleMoney() {
      this.form.realMoney = this.form.applyMoney - this.form.manageMoney - this.form.examineMoney - this.form.serviceMoney;
    }
  },
  filters: {
    numFilter: (value) => {
      return value = parseFloat(value * 100).toFixed(2)
    },
    numFilter1: (value) => {
      return value = parseFloat(value).toFixed(0)
    }
  }
};
</script>
<style lang="scss" scoped>
.panel-group {
  margin-top: 18px;

  .card-panel-col {
    margin-bottom: 32px;
  }

  .card-panel {
    height: 108px;
    cursor: pointer;
    font-size: 16px;
    position: relative;
    overflow: hidden;
    color: #666;
    background: #fff;
    box-shadow: 4px 4px 40px rgba(0, 0, 0, .05);
    border-color: rgba(0, 0, 0, .05);


    .card-panel-description {
      font-weight: bold;
      margin: 26px;
      margin-left: 0px;

      .card-panel-text {
        line-height: 18px;
        color: rgba(0, 0, 0, 0.45);
        font-size: 16px;
        margin-bottom: 12px;
      }

      .card-panel-num {
        font-size: 20px;
      }
    }
  }
}

@media (max-width: 550px) {
  .card-panel-description {
    display: none;
  }

  .card-panel-icon-wrapper {
    float: none !important;
    width: 100%;
    height: 100%;
    margin: 0 !important;

    .svg-icon {
      display: block;
      margin: 14px auto !important;
      float: none !important;
    }
  }
}
</style>
